home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer: Getting Started / Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin / pc / mac / bonus / peter_le / dehqx-20 / displayh.p < prev    next >
Text File  |  1991-08-23  |  5KB  |  193 lines

  1. unit DisplayHQX;
  2. { DeHQX v2.0.0 ⌐ Peter Lewis, Aug 1991 }
  3.  
  4. interface
  5.  
  6.     uses
  7.         FixMath, MyTypes, MyUtilities, MyFileSystem, MySystem7, MyLists, AppGlobals, Displays, HQXLists, ReadHQX;
  8.  
  9.     procedure OpenDisplay (var wp: windowPtr);
  10.     procedure DisplayOpen (wp: windowPtr; hi: hqxinfo);
  11.     procedure DisplayFork (wp: windowPtr; fork: forkType; i: longInt; oe: OSErr);
  12.     procedure DisplayFinish (wp: windowPtr; oe: OSErr);
  13.     procedure DisplayClose (wp: windowPtr);
  14.     procedure CloseDisplay (var wp: windowPtr);
  15.  
  16. implementation
  17.  
  18.     const
  19.         k_char = 1;
  20.         p_char = 2;
  21.         s_char = 3;
  22.         S_100Per = 1;
  23.         S_Failed = 2;
  24.         S_Chars = 3;
  25.         S_Looking = 4;
  26.         S_Dehqxing = 5;
  27.         DI_Progress = 1;
  28.         DI_Reading = 2;
  29.         DI_Status = 10;
  30.         DI_Name = 3;   { NB: Uses the fact that all info from Name to RsrcPer is cleared on DisplayClose }
  31.         DI_Creator = 4;
  32.         DI_Type = 5;
  33.         DI_DataSize = 6;
  34.         DI_DataPer = 7;
  35.         DI_RsrcSize = 8;
  36.         DI_RsrcPer = 9;
  37.  
  38.     type
  39.         hqxInfoX = record
  40.                 whivalid: boolean;
  41.                 whi: hqxInfo;
  42.                 wfork: forkType;
  43.                 doe, roe: integer;
  44.                 di, dlen, ri, rlen: longInt;
  45.             end;
  46.         hqxInfoXP = ^hqxInfoX;
  47.  
  48.     var
  49.         chars: string[3];
  50.  
  51.     function GetHqxInfoXP (wp: windowPtr): hqxInfoXP;
  52.     begin
  53.         GetHqxInfoXP := hqxInfoXP(GetWRefCon(wp));
  54.     end;
  55.  
  56.     function NumToK (n: longInt): str255;
  57.         var
  58.             s: str255;
  59.     begin
  60.         NumToString((n + 1023) div 1024, s);
  61.         s := Concat(s, chars[k_char]);
  62.         NumToK := s;
  63.     end;
  64.  
  65.     function GetDisplayStr (i: integer): str255;
  66.         var
  67.             s: str255;
  68.     begin
  69.         GetIndString(s, display_strh_id, i);
  70.         GetDisplayStr := s;
  71.     end;
  72.  
  73.     procedure OpenDisplay (var wp: windowPtr);
  74.         var
  75.             hixp: hqxInfoXP;
  76.             it: integer;
  77.             ih: handle;
  78.             box: rect;
  79.     begin
  80.         chars := GetDisplayStr(S_Chars);
  81.         wp := GetNewDialog(display_dialog_id, nil, POINTER(-1));
  82.         GetDItem(wp, DI_Progress, it, ih, box);
  83.         SetDItem(wp, DI_Progress, it, handle(@ProgressItem), box);
  84.         SetItemText(wp, DI_Status, GetDisplayStr(S_Looking));
  85.         hixp := POINTER(NewPtr(SizeOf(hqxInfoX)));
  86.         hixp^.whivalid := false;
  87.         SetWRefCon(wp, longInt(hixp));
  88.     end;
  89.  
  90.     procedure DisplayOpen (wp: windowPtr; hi: hqxInfo);
  91.         var
  92.             hixp: hqxInfoXP;
  93.             vrn: integer;
  94.             dirID: longInt;
  95.             fname: str63;
  96.             oe: OSErr;
  97.     begin
  98.         hixp := GetHqxInfoXP(wp);
  99.         hixp^.whi := hi;
  100.         SetItemText(wp, DI_Reading, processing_name);
  101.         SetItemText(wp, DI_Status, GetDisplayStr(S_Dehqxing));
  102.         SetItemText(wp, DI_Name, hi.name);
  103.         if hi.t = 'APPL' then begin
  104.             SetItemText(wp, DI_Creator, hi.c);
  105.             SetItemText(wp, DI_Type, 'Application');
  106.         end
  107.         else begin
  108.             if MyGetAPPL(hi.c, vrn, dirID, fname) = noErr then
  109.                 SetItemText(wp, DI_Creator, fname)
  110.             else
  111.                 SetItemText(wp, DI_Creator, hi.c);
  112.             SetItemText(wp, DI_Type, hi.t);
  113.         end;
  114.         SetItemText(wp, DI_DataSize, concat(NumToK(hi.dlen), chars[s_char]));
  115.         SetItemText(wp, DI_RsrcSize, concat(NumToK(hi.rlen), chars[s_char]));
  116.         hixp^.whivalid := true;
  117.         with hixp^ do begin
  118.             wfork := no_fork;
  119.             di := 0;
  120.             dlen := hi.dlen;
  121.             doe := noErr;
  122.             ri := 0;
  123.             rlen := hi.rlen;
  124.             roe := noErr;
  125.         end;
  126.     end;
  127.  
  128.     procedure DisplayClose (wp: windowPtr);
  129.         var
  130.             hixp: hqxInfoXP;
  131.             i: integer;
  132.     begin
  133.         hixp := GetHqxInfoXP(wp);
  134.         hixp^.whivalid := false;
  135.         SetItemText(wp, DI_Status, GetDisplayStr(S_Looking));
  136.         for i := DI_Name to DI_RsrcPer do
  137.             SetItemText(wp, i, '');
  138.     end;
  139.  
  140.     procedure CloseDisplay (var wp: windowPtr);
  141.         var
  142.             hixp: hqxInfoXP;
  143.     begin
  144.         hixp := GetHqxInfoXP(wp);
  145.         DisposPtr(ptr(hixp));
  146.         DisposDialog(wp);
  147.     end;
  148.  
  149.     procedure DisplayFork (wp: windowPtr; fork: forkType; i: longInt; oe: OSErr);
  150.         var
  151.             s1, s2: str255;
  152.             pp, item: integer;
  153.             len: longInt;
  154.     begin
  155. { Only called between DisplayOpen and DisplayClose }
  156.         ProgressItem(wp, DI_Progress);
  157.         SetItemText(wp, DI_Reading, processing_name);
  158.         with GetHqxInfoXP(wp)^ do begin
  159.             wfork := fork;
  160.             if fork = data_fork then begin
  161.                 di := i;
  162.                 len := dlen;
  163.                 doe := oe;
  164.                 item := DI_DataSize;
  165.             end
  166.             else begin
  167.                 item := DI_RsrcSize;
  168.                 ri := i;
  169.                 len := rlen;
  170.                 roe := oe;
  171.             end;
  172.         end;
  173.         if len = 0 then
  174.             s1 := GetDisplayStr(S_100Per)
  175.         else begin
  176.             NumToString((i * 100) div len, s1);
  177.             s1 := Concat(s1, chars[p_char]);
  178.         end;
  179.         SetItemText(wp, item + 1, s1);
  180.         if oe = noErr then
  181.             SetItemText(wp, item, concat(NumToK(len), chars[s_char], NumToK(i)))
  182.         else
  183.             SetItemText(wp, item, GetDisplayStr(S_Failed));
  184.     end;
  185.  
  186.     procedure DisplayFinish (wp: windowPtr; oe: OSErr);
  187.     begin
  188.         ProgressItem(wp, DI_Progress);
  189.         SetItemText(wp, DI_Reading, processing_name);
  190. { Only called between DisplayOpen and DisplayClose }
  191.     end;
  192.  
  193. end.